001    /*
002     * NeoBio.java
003     *
004     * Copyright 2003 Sergio Anibal de Carvalho Junior
005     *
006     * This file is part of NeoBio.
007     *
008     * NeoBio is free software; you can redistribute it and/or modify it under the terms of
009     * the GNU General Public License as published by the Free Software Foundation; either
010     * version 2 of the License, or (at your option) any later version.
011     *
012     * NeoBio is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
013     * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
014     * PURPOSE. See the GNU General Public License for more details.
015     *
016     * You should have received a copy of the GNU General Public License along with NeoBio;
017     * if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
018     * Boston, MA 02111-1307, USA.
019     *
020     * Proper attribution of the author as the source of the software would be appreciated.
021     *
022     * Sergio Anibal de Carvalho Junior             mailto:sergioanibaljr@users.sourceforge.net
023     * Department of Computer Science               http://www.dcs.kcl.ac.uk
024     * King's College London, UK                    http://www.kcl.ac.uk
025     *
026     * Please visit http://neobio.sourceforge.net
027     *
028     * This project was supervised by Professor Maxime Crochemore.
029     *
030     */
031    
032    package neobio.gui;
033    
034    import java.io.*;
035    import java.awt.*;
036    import java.awt.event.*;
037    import javax.swing.*;
038    import javax.swing.border.*;
039    import java.applet.*;
040    import java.util.*;
041    import java.net.URL;
042    import java.beans.PropertyVetoException;
043    
044    /**
045     * This class is a simple GUI utility for computing pairwise sequence alignments using one
046     * of the the algorithms provided in the {@link neobio.alignment} package.
047     *
048     * @author Sergio A. de Carvalho Jr.
049     */
050    public class NeoBio extends JFrame
051    {
052        private JMenu                       file_menu, help_menu;
053        private JMenuBar            menu_bar;
054        private JMenuItem           new_alignment_item, exit_menuitem, about_menuitem;
055        private JSeparator          mid_separator;
056        private JToolBar            file_toolbar;
057        private JPanel                      toolbar_panel;
058        private JButton                     alignment_button;
059    
060        private JDesktopPane        desktop_pane;
061    
062            /**
063             * Creates a new instance of a graphical interface.
064             */
065        public NeoBio()
066        {
067                    super();
068    
069            setTitle("NeoBio");
070            setDefaultCloseOperation (WindowConstants.DISPOSE_ON_CLOSE);
071            initComponents();
072    
073            show();
074    
075                    // always open pairwise alignment internal frame
076            pairwiseAlignment();
077        }
078    
079        private void initComponents()
080        {
081                    URL icon;
082    
083                    // window closing event
084            addWindowListener(new WindowAdapter()
085            {
086                public void windowClosing(WindowEvent e)
087                {
088                    exitForm();
089                }
090            });
091    
092                    Container content_pane = getContentPane();
093    
094                    desktop_pane = new JDesktopPane();
095    
096                    content_pane.add (desktop_pane, BorderLayout.CENTER);
097    
098            new_alignment_item = new JMenuItem("Pairwise Alignment");
099            new_alignment_item.setMnemonic('p');
100            new_alignment_item.addActionListener(new ActionListener()
101            {
102                public void actionPerformed(ActionEvent e)
103                {
104                    newAlignmentActionPerformed(e);
105                }
106            });
107            icon = getClass().getResource("icons/alignment.gif");
108            if (icon != null) new_alignment_item.setIcon(new ImageIcon(icon));
109    
110            mid_separator = new JSeparator();
111    
112            exit_menuitem = new JMenuItem("Exit");
113            exit_menuitem.setMnemonic('x');
114            exit_menuitem.addActionListener(new ActionListener()
115            {
116                public void actionPerformed(ActionEvent e)
117                {
118                    exitMenuItemActionPerformed(e);
119                }
120            });
121    
122            file_menu = new JMenu("File");
123            file_menu.setMnemonic('f');
124            file_menu.add(new_alignment_item);
125            file_menu.add(mid_separator);
126            file_menu.add(exit_menuitem);
127    
128            about_menuitem = new JMenuItem("About");
129            about_menuitem.addActionListener(new ActionListener()
130            {
131                public void actionPerformed(ActionEvent e)
132                {
133                    aboutMenuItemActionPerformed(e);
134                }
135            });
136            icon = getClass().getResource("icons/help.gif");
137            if (icon != null) about_menuitem.setIcon(new ImageIcon(icon));
138    
139            help_menu = new JMenu("Help");
140            help_menu.add(about_menuitem);
141    
142            menu_bar = new JMenuBar();
143            //menu_bar.setFont(getFont());
144            menu_bar.add(file_menu);
145            menu_bar.add(help_menu);
146    
147            setJMenuBar(menu_bar);
148    
149            alignment_button = new JButton();
150            alignment_button.setMnemonic('p');
151            alignment_button.setToolTipText("Pairwise Alignment...");
152            alignment_button.addActionListener(new ActionListener()
153            {
154                public void actionPerformed(ActionEvent e)
155                {
156                    newAlignmentActionPerformed(e);
157                }
158            });
159            icon = getClass().getResource("icons/alignment.gif");
160            if (icon != null) alignment_button.setIcon(new ImageIcon(icon));
161    
162            file_toolbar = new JToolBar();
163            file_toolbar.setRollover(true);
164            file_toolbar.add(alignment_button);
165    
166            toolbar_panel = new JPanel();
167                    toolbar_panel.setLayout(new FlowLayout(FlowLayout.LEFT, 0, 0));
168            toolbar_panel.setBorder(new EtchedBorder());
169            toolbar_panel.add(file_toolbar);
170    
171            content_pane.add(toolbar_panel, BorderLayout.NORTH);
172    
173                    // set frame size
174            Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
175            setSize((screen.width * 2) / 3, (screen.height * 7) / 8);
176                    setLocation(screen.width / 6, screen.height / 16);
177        }
178    
179        private void aboutMenuItemActionPerformed (ActionEvent e)
180        {
181            (new AboutDialog(this)).show();
182        }
183    
184        private void exitMenuItemActionPerformed (ActionEvent e)
185        {
186            exitForm();
187        }
188    
189        private void exitForm ()
190        {
191            System.exit(0);
192        }
193    
194        private void newAlignmentActionPerformed (ActionEvent e)
195        {
196                    pairwiseAlignment();
197        }
198    
199        private void pairwiseAlignment ()
200        {
201                PairwiseAlignmentFrame alignment_frame = new PairwiseAlignmentFrame (this);
202    
203            desktop_pane.add (alignment_frame);
204    
205            alignment_frame.setBounds(0, 0, 500, 500);
206            alignment_frame.show();
207            alignment_frame.toFront();
208    
209                    try
210                    {
211                            alignment_frame.setMaximum (true);
212                    }
213                    catch (PropertyVetoException e) {}
214            }
215    
216            /**
217             * Create and run a new interface.  The main method takes no parameter from the
218             * command line.
219             *
220             * @param args command line arguments
221             */
222        public static void main(String args[])
223        {
224            new NeoBio();
225        }
226    }